<!DOCTYPE html>
<%@page import="com.tdcy.sys.util.CodeTableUtils"%>
<%@page import="com.tdcy.framework.util.SessionUtils"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="biztag"%>
<html lang="en">
<head>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<jsp:include page="../../hcommon.jsp"></jsp:include>
</head>

<body class="white-bg" style="margin-left: 5px;margin-top: 5px;" >
	<form id="saveform" method="post" class="form-horizontal">
	  <table class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
	    <tbody>
	     <#list listColumn as column >
			 <tr>
	        <td class="width-15 active text-right">
	          <label>
	            <font color="red">*</font>${column.label} ：</label></td>
	        <td class="width-35">
	          <input id="${column.fieldName}" name="${column.fieldName}" class="form-control " datatype="*" nullmsg="不能为空"  />
	          <div class="Validform_checktip"></div>
	        </td>
	      </tr>
		</#list>
	    </tbody>
	  </table>
	</form>
	
	<div style="text-align: center;">
	 <button id="sbtn" class="btn btn-sm btn-primary" onclick="save();return false;"><i class="fa fa-plus"></i>保存</button>
	</div>
</body>


<script type="text/javascript">
	var data = AppKit.getInvokeWindowData();
	var operFlag=data.operFlag;
	var ${pkFieldId} = data.${pkFieldId};
	var formValid = null;
	
	$(document).ready(function() {
	    formValid = AppKit.formTipValidate("saveform");
	
		if(operFlag=="edit" ||operFlag=="detail"  ){
			$("#sbtn").show();
			 var url ="${r'${path}'}/${tableFirstName}/get${tableJavaClassName}Info";
			 AppKit.postJSON(url, {"${pkFieldId}": ${pkFieldId}}, querySuccess);
		}else{
			
		}
		
		if(operFlag=="detail" ){
			$("#sbtn").hide();
		}
	});

	function querySuccess(json)
	{
		if(!AppKit.checkJSONResult(json)){
	   		 return;
    	}	
		for(var i in json.data){
			$("#"+i).val(json.data[i]);
		}
	}
	
	function save()
	{
		var flag = formValid.check();
		if(!flag){
			return;
		}
		
		var info= $("#saveform").serializeObject();
		var url = "";
		if(operFlag == "add"){
			 url="${r'${path}'}/${tableFirstName}/add${tableJavaClassName}";
		}else if(operFlag == "edit"){
			info["${pkFieldId}"] = ${pkFieldId};
			url="${r'${path}'}/${tableFirstName}/update${tableJavaClassName}";
		}
	
		AppKit.postJSON(url,info, saveSuccess);
	}
	
	function saveSuccess(json){
		if(!AppKit.checkJSONResult(json)){
			return;
		}
		AppKit.showTipMessage(json.message,"",function(){
			AppKit.getInvokeWindow().reloadTable();
			AppKit.closeWindow();
		});
		
	}
	
</script>
</html>
